#ifndef COMMONHEADER_H_
#define COMMONHEADER_H_
#include <iostream>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <sstream>
#include <fstream>
#include <stdlib.h>
#include <algorithm>
#include <stdio.h>
#include <ctime>
#include <dirent.h>
#include <malloc.h>
#include <errno.h>
#include <time.h>
using namespace std;

#define MAX_FILE_NAME_LEN 255
#define FEATURE_NUM 150 //feature num
#define NEIGHB_NUM 31  //neighbor num
#define SAVE_NEIGHB_NUM 1000 // save neight num
typedef std::pair<int,double> mypair;
#include "../util/ConfigFile.h"
#include "RelatedQuestions.h"
#include "../util/util.h"
#include "DBBase.h"
#include "Cluster.h"
#include "SimTable.h"
#include "SampleQuestion.h"
extern ConfigFile g_config;
extern DBBase g_db;

int loadInLink(const char*, vector<int>&);
void calSimAndSave(vector< vector<float> > &matrix, int itemNum, const char* dstFile, 
        int start, int end, string simFun, RelatedQuestions &relateQuestions);
void calTFIDFSimAndSave(vector< map<int, float> >& matrix, int itemNum, const char* dstFile, 
        int start, int end, string simFun, RelatedQuestions &relateQuestions);
int loadTfidfFeatures(vector< map<int, float> >& matrix, const char* srcFile);
int loadLatentFeatures(vector< vector<float> >& matrix, const char* srcFile);
double inverseInLink(double sim, int inlinkNum);
vector<mypair> getKmax(vector<mypair>& array, int K);
bool comparator(const mypair& l, const mypair& r);
double getCosine(vector<float>& p, vector<float>& q, int featureStart, int featureEnd);

#endif // COMMONHEADER_H_
